package com.hht.baselibs.adapter

import androidx.annotation.LayoutRes
import androidx.databinding.ViewDataBinding
import com.hht.baselibs.listener.BaseAdapterItemListener


/**
 * Author:chen'hu
 * Time:2023/8/9 15:04
 * Description:This is CommonAdapter
 */
class CommonAdapter<DB : ViewDataBinding, T> : BaseAdapter<DB, T>() {

    private lateinit var viewBindBean: (DB, T) -> Unit

    fun setViewModelBindBean(function: (DB, T) -> Unit): CommonAdapter<DB, T> {
        viewBindBean = function
        return this
    }

    fun setLayoutResId(@LayoutRes layoutRes: Int): CommonAdapter<DB, T> {
        this.mLayoutResId = layoutRes
        return this
    }

    fun setAdapterDataList(mList: List<T>): CommonAdapter<DB, T> {
        this.dataList = mList
        return this
    }


    /***
     * @param drag true时，可以被拖拽，不可以监听，为false时，可以监听，不能被拖拽
     */
    fun setDrag(drag: Boolean): CommonAdapter<DB, T> {
        this.isOnDrag = drag
        return this
    }

    fun setAdapterItemListener(listener: BaseAdapterItemListener<T>): CommonAdapter<DB, T> {
        this.itemClickListener = listener
        return this

    }

    fun setOnItemClickListener(listener: (T) -> Unit): CommonAdapter<DB, T> {
        this.mOnBaseItemClickListener = listener
        return this
    }

    override fun getLayoutResId(): Int {
        return mLayoutResId
    }

    override fun getAdapterDataList(): List<T> {
        return dataList
    }

    override fun getDrag(): Boolean {
        return isOnDrag
    }

    override fun getAdapterItemClickListener(): BaseAdapterItemListener<T>? {
        return itemClickListener
    }

    override fun bindViewHolder(viewDataBinding: DB, t: T) {
        viewBindBean(viewDataBinding, t)
    }

    override fun getOnItemClickListener(): OnBaseItemClickListener<T>? {
      return mOnBaseItemClickListener
    }
}